package part12;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * @author wcj
 * @Date 2021/5/21 17:17
 * @Version 1.0
 */
public class Part1213 {

    private BufferedReader in;

    public Part1213(String fileName) throws Exception {

        try {
            in = new BufferedReader(new FileReader(fileName));
        } catch (FileNotFoundException e) {
            System.out.println("can't open " + fileName);
            throw e;
        } catch (Exception e) {
            try {
                in.close();
            } catch (IOException e2) {
                System.out.println("in.close not success");
            }
            throw e;
        } finally {

        }
    }

    public String getLine() {
        String s;
        try {
            s = in.readLine();
        } catch (IOException e) {
            throw new RuntimeException("readLine failed");
        }
        return s;
    }

    public void dispose() {
        try {
            in.close();
            System.out.println("dispose not success");
        } catch (IOException e) {
            throw new RuntimeException("in.close failed");
        }
    }
}
